const { DataTypes } = require('sequelize');
const { sequelize } = require('../utils/sequelize');
const config = require('../config/database');

// 用户模型
const User = sequelize.define(
  'BidUser', // 模型名称
  {
    id: {
      type: DataTypes.STRING(50),
      primaryKey: true,
      comment: '用户ID'
    },
    username: {
      type: DataTypes.STRING(50),
      allowNull: false,
      comment: '用户名'
    },
    password: {
      type: DataTypes.STRING(100),
      allowNull: false,
      comment: '密码（加密存储）'
    },
    phone: {
      type: DataTypes.STRING(20),
      allowNull: true,
      comment: '手机号'
    },
    avatar: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: '头像URL'
    },
    status: {
      type: DataTypes.TINYINT,
      defaultValue: 1,
      comment: '状态（1:正常, 0:禁用）'
    }
  },
  {
    tableName: config.mysql.prefix + 'users',
    timestamps: true,
    createdAt: 'created_at',
    updatedAt: 'updated_at',
    indexes: [
      { fields: ['phone'], name: 'idx_phone' }
    ],
    comment: '用户表'
  }
);

module.exports = User;